﻿// -----------------------------------------------------------------------
// <copyright file="EnergySource.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Ex03.GarageLogic
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public abstract class EnergySource
    {
        protected float m_CurrentEnergyLevel;
        protected float m_MaxEnergyLevel;

        internal float CurrentEnergyLevel
        {
            get { return m_CurrentEnergyLevel; }
            set { m_CurrentEnergyLevel = value; }
        }

        internal float MaxEnergyLevel
        {
            get { return m_MaxEnergyLevel; }
            set { m_MaxEnergyLevel = value; }
        }

        /// <summary>
        /// Collects data about a specific vehicle engine into a string format
        /// </summary>
        /// <param name="o_VehicleData">string in which the data is collected</param>
        internal void GetEngineData(ref StringBuilder o_VehicleData)
        {
            if (this is Fuel)
            {
                Fuel fuelEngine = (Fuel) this;
                o_VehicleData.AppendFormat(
                    "{0}Fuel tank contains: {1} liters{0}Max fuel tank is: {2} liters{0}Fuel type: {3}{0}",
                    Environment.NewLine,
                    fuelEngine.CurrentEnergyLevel.ToString(),
                    fuelEngine.MaxEnergyLevel.ToString(),
                    fuelEngine.FuelType.ToString());
            }
            else if (this is Electric)
            {
                Electric electricEngine = (Electric) this;
                o_VehicleData.AppendFormat(
                    "{0}Battery life time remains: {1} hours {0}Max battery life time is: {2} hours{0}",
                    Environment.NewLine,
                    electricEngine.CurrentEnergyLevel,
                    electricEngine.MaxEnergyLevel);
            }
        }

        public static eEngineTypes ConvertToEnergySourceEnum(string i_energySource)
        {
            eEngineTypes usersInputEnum = (eEngineTypes)Enum.Parse(typeof(eEngineTypes), i_energySource);
            if (Enum.IsDefined(typeof(eEngineTypes), usersInputEnum) == false)
            {
                throw new ArgumentException("There is no such option");
            }

            return usersInputEnum;
        }
    }
}
